package com.taotao.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.taotao.common.EasyUITreeNavResult;
import com.taotao.mapper.MainnavMapper;
import com.taotao.pojo.Mainnav;
import com.taotao.pojo.MainnavExample;
import com.taotao.pojo.MainnavExample.Criteria;
import com.taotao.service.MainNavService;

@Service
public class MainNavServiceImpl implements MainNavService{

	@Autowired
	private MainnavMapper mainnavMapper;
	
	@Override
	public List<EasyUITreeNavResult> getMainNav(long parentNavId) {
		List<EasyUITreeNavResult> result = new ArrayList<EasyUITreeNavResult>();
		// 根据treeNavId查询分类列表
		MainnavExample mainnavExample = new MainnavExample();
		Criteria createCriteria = mainnavExample.createCriteria();
		createCriteria.andParentIdEqualTo(parentNavId);
		// 执行查询
		List<Mainnav> list = mainnavMapper.selectByExample(mainnavExample);
		// 转换成EasyUITreeNavResult
		for (Mainnav mainNav : list) {
			EasyUITreeNavResult easyUITreeNavResult = new EasyUITreeNavResult();
			easyUITreeNavResult.setId(mainNav.getId());
			easyUITreeNavResult.setText(mainNav.getName());
			easyUITreeNavResult
					.setState(mainNav.getIsParent() ? "parent" : "");
			easyUITreeNavResult.setIconCls(mainNav.getIconcls());
			// 构建attributes
			Map<String,Object> attributes = new HashMap<String, Object>();
			attributes.put("url", mainNav.getAttributes());
			easyUITreeNavResult.setAttributes(attributes);
			result.add(easyUITreeNavResult);
		}
		return result;
	}

}
